package com.yzt.zhuju.network.biz;

import com.alibaba.fastjson.JSONObject;
import com.yzt.zhuju.network.NetLayer;
import com.yzt.zhuju.network.apiconfig.DynamicUrlConstant;
import com.yzt.zhuju.network.apiconfig.IndexUrlConstant;

import rx.Observable;
import rx.Observer;

/**
 * author : bob
 * date   : 2022/12/6
 * desc   : 首页
 */
public class IndexModule extends BaseModule {

    /**
     * 获取首页列表数据
     * 类型 1-发现 2-关注 3-动态
     */
    public void getIndexUserList(int type, String cityCode, String lat, String lon, int page, int size, Observer observer) {

        Observable observable;

        JSONObject json = new JSONObject();
        json.put("current", page);
        json.put("pageSize", size);

        if (cityCode != null) {
            json.put("cityCode", cityCode);
            json.put("lat", lat);
            json.put("lon", lon);
        }

        if (type == 1) {
            observable = NetLayer.getInstance().getIndexService().getIndexUserList(getRequestBody(json));
            toSubscribe2Filter(observable, observer, IndexUrlConstant.GET_INDEX_RECOMMEND);
        } else if (type == 2) {
            observable = NetLayer.getInstance().getIndexService().getIndexFollowList(getRequestBody(json));
            toSubscribe2Filter(observable, observer, IndexUrlConstant.GET_INDEX_FOLLOW);
        } else {
            observable = NetLayer.getInstance().getIndexService().getIndexDynamicList(getRequestBody(json));
            toSubscribe2Filter(observable, observer, IndexUrlConstant.GET_INDEX_DYNAMIC);
        }
    }

    /**
     * 可播放的动态列表
     */
    public void getIndexUserList(String userId, String dynamicId, int page, int size, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("userId", userId);
        json.put("dynamicId", dynamicId);
        json.put("current", page);
        json.put("pageSize", size);
        Observable observable = NetLayer.getInstance().getIndexService().getDynamicByUserList(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.GET_DYNAMIC_LIST);
    }

    /**
     * 游戏列表
     */
    public void getUserGameList(String userId, int page, int size, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("current", page);
        json.put("pageSize", size);
        json.put("userId", userId);
        Observable observable = NetLayer.getInstance().getIndexService().getUserGameList(getRequestBody(json));
        toSubscribe2Filter(observable, observer, IndexUrlConstant.GET_GAME_LIST);
    }
}
